using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_Credit : Shop, IRequiresSessionState
{
	public string ShopAdImage = "";
	private string _OrderFormNum = "";
	private int _IsSaler = -1;
	private int _ByValuerID = 0;
	protected int JustValuerCredit = 1;
	protected int JustSBCredit = 0;
	private int _CreditInfoID = 0;
	private string _actioninfo = "";
	protected HtmlImage headImg;
	protected Literal ltrshop;
	protected Literal ltrBuy;
	protected Label lbWho;
	protected Repeater Repeater1;
	protected RadioButton RadioOk;
	protected RadioButton Radionormal;
	protected RadioButton Radiobad;
	protected CheckBox CheckNotName;
	protected RadioButtonList RBLCommentType;
	protected TextBox txtCommentBox;
	protected FileUpload FileUpload1;
	protected HiddenField hfCommentPicture;
	protected TextBox txtCommentPicture;
	protected TextBox txtCommentVideo;
	protected Button butOK;
	protected HiddenField HiProductName;
	protected PlaceHolder PlaceHolder1;
	public string OrderFormNum
	{
		get
		{
			if (base.Request.QueryString["OrderFormNum"] != null)
			{
				this._OrderFormNum = base.Request.QueryString["OrderFormNum"];
			}
			return this._OrderFormNum;
		}
	}
	public int IsSaler
	{
		get
		{
			if (base.Request.QueryString["IsBuySaler"] != null)
			{
				this._IsSaler = int.Parse(base.Request.QueryString["IsBuySaler"]);
			}
			return this._IsSaler;
		}
	}
	public int ByValuerID
	{
		get
		{
			return this._ByValuerID;
		}
		set
		{
			this._ByValuerID = value;
		}
	}
	public int CreditInfoID
	{
		get
		{
			if (base.Request.QueryString["CreditInfoID"] != null)
			{
				string value = base.Request.QueryString["CreditInfoID"].ToString();
				if (!string.IsNullOrEmpty(value))
				{
					this._CreditInfoID = Convert.ToInt32(value);
				}
			}
			return this._CreditInfoID;
		}
	}
	public string actioninfo
	{
		get
		{
			this._actioninfo = base.ActionTabInfo;
			return this._actioninfo;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (this.IsSaler == 1)
		{
			this.ByValuerID = this.GetSalerBuyID()[0];
			this.JustSBCredit = 1;
			this.JustValuerCredit = 0;
		}
		else
		{
			if (this.IsSaler == 0)
			{
				this.ByValuerID = this.GetSalerBuyID()[1];
				this.JustSBCredit = 0;
				this.JustValuerCredit = 1;
			}
		}
		if (!base.IsPostBack)
		{
			if (this.actioninfo == "editinfo")
			{
				if (base.user.UserID > 0)
				{
					this.ShowUserInfo();
					this.ShowProductName();
					if (this.CreditInfoID > 0)
					{
						this.InitCreditInfo();
					}
				}
			}
			else
			{
				if (this.IsSaler != -1)
				{
					int num = 0;
					string sql = "select DeliverStatus,Status from HLShop_Order where OrderFormNum='" + this.OrderFormNum + "'";
					DataTable dataTable = this.conn.GetDataTable(sql);
					if (dataTable != null && dataTable.Rows.Count >= 0)
					{
						if (dataTable.Rows[0]["DeliverStatus"] != DBNull.Value)
						{
							int num2 = Convert.ToInt32(dataTable.Rows[0]["DeliverStatus"].ToString());
						}
						if (dataTable.Rows[0]["Status"] != DBNull.Value)
						{
							num = Convert.ToInt32(dataTable.Rows[0]["Status"].ToString());
						}
						if (num != 2)
						{
							this.WriteErrMsg("", "该订单未完成,还不能评价！", "");
						}
					}
					this.ShowUserInfo();
					this.ShowProductName();
				}
				else
				{
					this.WriteErrMsg("", "你没有权限进去评价！", "");
				}
			}
		}
	}
	public void ShowUserInfo()
	{
		this.ShopAdImage = "../Images/nopicture.gif";
		if (this.GetSalerBuyID()[0] == base.user.UserID)
		{
			DataTable dataTable = this.conn.GetDataTable("select UserName from HL_User where UserID=" + this.GetSalerBuyID()[1]);
			this.ltrBuy.Text = "被评价的卖家:";
			this.lbWho.Text = dataTable.Rows[0]["UserName"].ToString();
			DataTable dataTable2 = this.conn.GetDataTable("select * from HLShop_Shop where ShopOwnerID=" + this.GetSalerBuyID()[1]);
			if (dataTable2 != null && dataTable2.Rows.Count != 0)
			{
				this.ltrshop.Text = string.Concat(new string[]
				{
					"<a href='../Store/ShopIndex.aspx?ShopID=",
					dataTable2.Rows[0]["ShopID"].ToString(),
					"' target='_blank'>",
					dataTable2.Rows[0]["ShopName"].ToString(),
					"</a>"
				});
				if (dataTable2.Rows[0]["ShopImageUrl"] != DBNull.Value)
				{
					this.headImg.Src = dataTable2.Rows[0]["ShopImageUrl"].ToString();
				}
			}
			dataTable2.Dispose();
			dataTable.Dispose();
		}
		else
		{
			DataTable dataTable3 = this.conn.GetDataTable("select UserName from HL_User where UserID=" + this.GetSalerBuyID()[0]);
			this.ltrBuy.Text = "被评价的买家:";
			this.lbWho.Text = dataTable3.Rows[0]["UserName"].ToString();
			DataTable dataTable2 = this.conn.GetDataTable("select * from HLShop_Shop where ShopOwnerID=" + this.GetSalerBuyID()[1]);
			if (dataTable2 != null && dataTable2.Rows.Count != 0)
			{
				this.ltrshop.Text = string.Concat(new string[]
				{
					"<a href='../Store/ShopIndex.aspx?ShopID=",
					dataTable2.Rows[0]["ShopID"].ToString(),
					"' target='_blank'>",
					dataTable2.Rows[0]["ShopName"].ToString(),
					"</a>"
				});
				if (dataTable2.Rows[0]["ShopImageUrl"] != DBNull.Value)
				{
					this.headImg.Src = dataTable2.Rows[0]["ShopImageUrl"].ToString();
				}
			}
			dataTable2.Dispose();
			dataTable3.Dispose();
		}
	}
	public int[] GetSalerBuyID()
	{
		int[] array = new int[2];
		DataTable dataTable = this.conn.GetDataTable("select UserID,SalerID from HLShop_Order where  OrderFormNum='" + this.OrderFormNum + "'");
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			array[0] = int.Parse(dataTable.Rows[0]["UserID"].ToString());
			array[1] = int.Parse(dataTable.Rows[0]["SalerID"].ToString());
		}
		dataTable.Dispose();
		return array;
	}
	public void ShowProductName()
	{
		DataTable dataTable = this.conn.GetDataTable("select a.ProductName as ProName,b.ProductID as PID,* from HLShop_OrderItem as a,HLShop_Product as b where a.ProductID=b.ProductID and a.OrderFormNum='" + this.OrderFormNum + "'");
		this.Repeater1.DataSource = dataTable;
		this.Repeater1.DataBind();
		for (int i = 0; i < dataTable.Rows.Count; i++)
		{
			HiddenField expr_49 = this.HiProductName;
			expr_49.Value += dataTable.Rows[i]["ProName"].ToString();
		}
		dataTable.Dispose();
	}
	protected void InitCreditInfo()
	{
		if (this.CreditInfoID > 0)
		{
			string sql = "select * from HLMall_Credit where CreditID=" + this.CreditInfoID;
			DataTable dataTable = this.conn.GetDataTable(sql);
			if (dataTable != null)
			{
				if (dataTable.Rows.Count > 0)
				{
					DataRow dataRow = dataTable.Rows[0];
					this.RadioOk.Checked = true;
					this.Radionormal.Enabled = false;
					this.Radiobad.Enabled = false;
					string value = "";
					if (dataTable.Columns.Contains("ValuerName"))
					{
						if (dataRow["ValuerName"] != DBNull.Value)
						{
							value = dataRow["ValuerName"].ToString().Trim();
						}
					}
					if (string.IsNullOrEmpty(value))
					{
						this.CheckNotName.Checked = true;
					}
					string text = "";
					if (dataTable.Columns.Contains("commentType"))
					{
						if (dataRow["commentType"] != DBNull.Value)
						{
							text = dataRow["commentType"].ToString().Trim();
						}
					}
					string text2 = "";
					if (dataTable.Columns.Contains("commentTypeURL"))
					{
						if (dataRow["commentTypeURL"] != DBNull.Value)
						{
							text2 = dataRow["commentTypeURL"].ToString().Trim();
						}
					}
					string text3 = "";
					if (dataTable.Columns.Contains("Comment"))
					{
						if (dataRow["Comment"] != DBNull.Value)
						{
							text3 = dataRow["Comment"].ToString();
						}
					}
					for (int i = 0; i < this.RBLCommentType.Items.Count; i++)
					{
						this.RBLCommentType.Items[i].Selected = false;
					}
					this.RBLCommentType.rblSelect(text);
					string text4 = text;
					if (text4 != null)
					{
						if (!(text4 == "txt"))
						{
							if (!(text4 == "picture"))
							{
								if (text4 == "video")
								{
									this.txtCommentVideo.Text = text2;
								}
							}
							else
							{
								string[] contentArray = text2.Split(new char[]
								{
									'$'
								});
								string contentByName = StaticFun.GetContentByName("picture", contentArray);
								string contentByName2 = StaticFun.GetContentByName("pictureText", contentArray);
								if (!string.IsNullOrEmpty(contentByName))
								{
									this.hfCommentPicture.Value = contentByName;
								}
								this.txtCommentPicture.Text = contentByName2;
							}
						}
						else
						{
							this.txtCommentBox.Text = text3;
						}
					}
				}
			}
		}
	}
	protected void butOK_Click(object sender, EventArgs e)
	{
		int num = -2;
		int num2 = 0;
		string rBLValue = this.RBLCommentType.GetRBLValue();
		if ((rBLValue == "txt" || rBLValue == "picture") && this.txtCommentBox.Text.Length > 250)
		{
			base.ClientScript.RegisterClientScriptBlock(typeof(Page), "", "<script>alert('评价内容已超过250字！')</script>");
		}
		else
		{
			if (this.Radionormal.Checked)
			{
				if (rBLValue == "txt" && (this.txtCommentBox.Text == "" || this.txtCommentBox.Text == "咳咳！你给对方中评，需要说明理由哦"))
				{
					base.ClientScript.RegisterClientScriptBlock(typeof(Page), "", "<script>alert('你给对方中评，需要说明理由！')</script>");
					return;
				}
				num = 0;
			}
			else
			{
				if (this.Radiobad.Checked)
				{
					if (rBLValue == "txt" && (this.txtCommentBox.Text == "" || this.txtCommentBox.Text == "咳咳！你给对方差评，需要说明理由哦"))
					{
						base.ClientScript.RegisterClientScriptBlock(typeof(Page), "", "<script>alert('你给对方差评，需要说明理由！')</script>");
						return;
					}
					num = -1;
				}
				else
				{
					if (this.RadioOk.Checked)
					{
						if (rBLValue == "txt" && this.txtCommentBox.Text == "写点评价吧！你评价对对方有很大的帮助哦")
						{
							this.txtCommentBox.Text = "";
						}
						num = 1;
					}
				}
			}
			if (num == -2)
			{
				MessageBox.Show(this, "请选择评价等级！");
			}
			else
			{
				string text = "";
				if (rBLValue == "picture")
				{
					if (this.actioninfo == "editinfo")
					{
						if (this.FileUpload1.HasFile)
						{
							UploadFile uploadFile = new UploadFile("/UpLoadFile/CommentPicture");
							uploadFile.Extension = ".png,.jpg,.gif,.bmp";
							string text2 = uploadFile.DoUploadFile(this.FileUpload1, true, new string[0]);
							if (text2 != "")
							{
								MessageBox.Show(this, "保存图片失败！操作取消：" + text2);
								return;
							}
							text = uploadFile.FileName;
						}
						else
						{
							if (string.IsNullOrEmpty(this.hfCommentPicture.Value))
							{
								MessageBox.Show(this, "请选择一张图片上传。");
								return;
							}
							text = this.hfCommentPicture.Value;
						}
					}
					else
					{
						if (!this.FileUpload1.HasFile)
						{
							MessageBox.Show(this, "请选择一张图片上传。");
							return;
						}
						UploadFile uploadFile = new UploadFile("/UpLoadFile/CommentPicture");
						uploadFile.Extension = ".png,.jpg,.gif,.bmp";
						string text2 = uploadFile.DoUploadFile(this.FileUpload1, true, new string[0]);
						if (text2 != "")
						{
							MessageBox.Show(this, "保存图片失败！操作取消：" + text2);
							return;
						}
						text = uploadFile.FileName;
					}
				}
				string text3 = "";
				string text4 = "";
				string text5 = rBLValue;
				if (text5 != null)
				{
					if (!(text5 == "txt"))
					{
						if (!(text5 == "picture"))
						{
							if (text5 == "video")
							{
								if (this.txtCommentVideo.Text.Trim() != "")
								{
									text4 = this.txtCommentVideo.Text;
									text3 = "<embed src=\"" + this.txtCommentVideo.Text + "\" quality=\"high\" width=\"480\" height=\"400\" align=\"middle\" allowscriptaccess=\"always\" allowfullscreen=\"true\" mode=\"transparent\" type=\"application/x-shockwave-flash\"></embed>";
								}
							}
						}
						else
						{
							if (text != "")
							{
								text4 = string.Concat(new string[]
								{
									rBLValue,
									"#",
									text,
									"$pictureText#",
									this.txtCommentPicture.Text
								});
								text3 = "<img style=\"width:480px;height:400px\" src=\"/UpLoadFile/CommentPicture/" + text + "\"/><br/>" + this.txtCommentPicture.Text;
							}
						}
					}
					else
					{
						if (this.txtCommentBox.Text.Trim() != "")
						{
							text3 = this.txtCommentBox.Text;
						}
					}
				}
				if (text3 == "" && num < 1)
				{
					MessageBox.Show(this, "您选择了差评或中评，请填写理由！");
				}
				else
				{
					string text6 = "";
					if (!this.CheckNotName.Checked)
					{
						text6 = base.user.UserName;
					}
					if (this.actioninfo == "editinfo")
					{
						string sql = string.Concat(new object[]
						{
							"UPDATE [HLMall_Credit] SET [ValuerName] ='",
							text6,
							"',[ValuerID] =",
							base.user.UserID,
							" ,[CreditScore]= ",
							num,
							" ,[Comment] ='",
							text3,
							"',[commentType] = '",
							rBLValue,
							"',[commentTypeURL] = '",
							text4,
							"' WHERE CreditID=",
							this.CreditInfoID
						});
						int num3 = this.conn.Execute(sql);
						if (num3 > 0)
						{
							this.WriteSuccessMsg("", "评价信息修改成功！", "Shop_myRate.aspx");
						}
						else
						{
							string comeUrl = string.Concat(new object[]
							{
								"CreditComment.aspx?OrderFormNum=",
								this.OrderFormNum,
								"&Action=editinfo&CreditInfoID=",
								this.CreditInfoID
							});
							this.WriteSuccessMsg("", "评价信息修改失败！", comeUrl);
						}
					}
					else
					{
						if (!this.JustCommented())
						{
							try
							{
								num2 = this.conn.Execute(string.Concat(new object[]
								{
									"insert into HLMall_Credit (OrderFormNum,ProductName,ValuerName,ValuerID,ByValuerID,JustSBCredit,JustValuerCredit,CreditScore,CreateTime,Comment,commentType,commentTypeURL) values('",
									this.OrderFormNum,
									"','",
									this.HiProductName.Value,
									"','",
									text6,
									"',",
									base.user.UserID,
									",",
									this.ByValuerID,
									",",
									this.JustSBCredit,
									",",
									this.JustValuerCredit,
									",",
									num,
									",'",
									DateTime.Now,
									"','",
									text3,
									"','",
									rBLValue,
									"','",
									text4,
									"')"
								}));
							}
							catch (Exception ex)
							{
								ex.WriteErrorLog(new string[]
								{
									"正常操作"
								});
								num2 = 0;
							}
							if (num2 >= 1)
							{
								this.WriteSuccessMsg("", "评价成功！", "Shop_myRate.aspx");
							}
							else
							{
								base.ClientScript.RegisterClientScriptBlock(typeof(Page), "", "<script>alert('评价失败！')</script>");
							}
						}
						else
						{
							base.ClientScript.RegisterClientScriptBlock(typeof(Page), "", "<script>alert('你已评价，不需再评价！')</script>");
						}
					}
				}
			}
		}
	}
	public bool JustCommented()
	{
		return this.conn.ExecuteCount(string.Concat(new object[]
		{
			"select count(*) from HLMall_Credit where ValuerID=",
			base.user.UserID,
			" and OrderFormNum='",
			this.OrderFormNum,
			"'"
		})) > 0;
	}
}
